package io.alvin.ch02;

/**
 * Join Demo
 * join()的本质是让调用线程wait()在当前线程对象实例上。JDK中join()实现的核心代码
 * while (isAlive()) {
 *     wait(0);
 * }
 * Created by Alvin on 2017/7/6.
 */
public class JoinMain {

    public volatile static int i = 0;

    public static class AddThread extends Thread {
        @Override
        public void run() {
            for (i = 0; i < 1000000; i++);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        AddThread t =  new AddThread();
        t.start();
        t.join();
        System.out.println(i);
    }

}
